[#ftl]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>数据项</title> 
 
<script type="text/javascript">
var updDialog;
 
 //双击编辑
	var $newNode=$("<input type='text' id='release_activate_count_input' class='input_1'>"); 
	var timeNode=$("<input type='text' id='release_time_input' class='input_1' onclick=\"WdatePicker({dateFmt:'yyyy-MM-dd'})\" >"); 
    var varietyNode=$("<select class='input_1' name='variety'>[#if dictItems??][#list dictItems as item]<option value='${item.value}'>${item.name}</option>[/#list][/#if]</select>");
    var $oldTdObj="";   //用于保存TD对象  
    
    function editItem(param){
            $(param).parents("tr").children('td').eq(4).find('a').remove();
            $(param).parents("tr").find("td").eq(4).append("<a href='javaScript:void(0);' onclick='saveEdit(this)' class='no_tdn color_2'>保存</a><a href='javaScript:void(0)' onclick='cancelEdit(this)' class='no_tdn pl10 color_2'>取消</a>");
            var $oldValue=$(param).text(); 
               //获取当前TD的值  
            var $ifInput=$(param).children().is('input');  //是否存在input  
            if($oldTdObj!=""){  
                var newValue=$("#release_activate_count_input").val();   
                $oldTdObj.text(newValue);  
            }  
             if(!$ifInput){ 
		                $(param).text('');  
		                $oldTdObj=$(param);                
		                $newNode.val($.trim($oldValue));  
		                $(param).append($newNode);
		                $newNode.focus(); 
	              
            }  
    
    }
    

// 注册各种事件
$(function() {

	$("#exportExcel").click(function(){
		 window.location.href="${base}/datacenter/exchangeRate/excel";
	});
	
	$("#thisAdd").click(function(){
	   $("#addItem").show();
	});
	$("#callBack").click(function(){
	   window.location.href="${base}/system/dictions?module=${module}";
	});
	
	//删除start
   $("#uDelete").click(function(){
   
		var projid = [];
		var status = [];
		$("input[name='cb']").each(function(){
			if($(this).attr("checked")=="checked"){
				projid.push($(this).attr("mid"));
			}
		});
		// 检查是否选择一个
		var len = $("input[type='checkbox'][name='cb']:checked").length;
		if ( len== 0) {
			var d=dialog({
            	content: '请选择一条数据！',
                icon: 'succeed',
                fixed: true,
                lock: true,
            });
            d.show();
            setTimeout(function () {
			    d.close().remove();
			}, 2000);
	        return false;
	     }
		else{		
		        deleteY(projid,len);		    
		}
});
		
});
//确认删除start
function deleteY(param,len){
  if (confirm("确定要删除这"+len+"项数据吗？")) {
  $.ajax({
	       type : "post",
	       url : "${base}/system/dictionary/deleteItem/"+param,
		   traditional:true,
		   dataType: "json",
		   success: function(data){	
		    noty({
                          text:extendMessages(data).msg.message,
                          layout:"center",
                          timeout:2000,
                          callback:{
                             afterClose:function(){
                                     refresh();
                                        }
                           }
               });
			},
			error:function(){
			}
		});	
}	     
}
//确认删除end

function refresh(){
   var dictId=$("#dictId").val();
   window.location.href="${base}/system/dictionary/dictItems/"+dictId+"?module=${module}";
}

function validItem(data){
    if(data[0]==null||data[0]==""){
	   var d=dialog({
            	content: '名称不能为空！',
                icon: 'succeed',
                fixed: true,
                lock: true,
            });
            d.show();
            setTimeout(function () {
			    d.close().remove();
			}, 2000);
	        return false;
	}else if(data[1]==null||data[1]==""){
	   var d=dialog({
            	content: '代码不能为空！',
                icon: 'succeed',
                fixed: true,
                lock: true,
            });
            d.show();
            setTimeout(function () {
			    d.close().remove();
			}, 2000);
	        return false;
	}else if(data[2]==null||data[2]==""){
	   var d=dialog({
            	content: '值不能为空！',
                icon: 'succeed',
                fixed: true,
                lock: true,
            });
            d.show();
            setTimeout(function () {
			    d.close().remove();
			}, 2000);
	        return false;
	}else if(data[3]==null||data[3]==""){
	   var d=dialog({
            	content: '次序不能为空！',
                icon: 'succeed',
                fixed: true,
                lock: true,
            });
            d.show();
            setTimeout(function () {
			    d.close().remove();
			}, 2000);
	        return false;
	}else{return true;}
}

function saveAdd(param){ 
   var dictId=$("#dictId").val();
    var data=[];
    for(var i=0;i<4;i++){
       var ifEdit=$(param).parent().parent().children('td').eq(i).find("input:eq(0)").length ;
           if(ifEdit==0){
            data.push($.trim($(param).parent().parent().find("td").eq(i).html()));
            }  
            else{  
                var newValue=$(param).parent().parent().children('td').eq(i).find("input:eq(0)").val();  
                data.push(newValue);  
            }
    }         
	if(validItem(data))
	  {
         $.ajax({ type:"post",
                url:"${base}/system/dictionary/dictItem/add",
                datatype:"json",
                data:{
                      "dictId":dictId,
                      "name":data[0],
                      "code":data[1],
                      "value":data[2],
                      "showOrder":data[3]
                },                
				success: function(data){  
					noty({
	                         text:extendMessages(data).msg.message,
	                          layout:"center",
	                          timeout:2000,
	                          callback:{
	                             afterClose:function(){
	                                     refresh();
	                                        }
	                           }
	               });
               }
			});		
	  }       
}

function saveEdit(param){
var dictId=$("#dictId").val();
    var id=$(param).parent().parent().find("input:eq(0)").attr("value");
    var data=[];
    for(var i=0;i<4;i++){
       var ifEdit=$(param).parent().parent().children('td').eq(i).find("input:eq(0)").length ;
           if(ifEdit==0){
            data.push($.trim($(param).parent().parent().find("td").eq(i).html()));
            }  
            else{  
                var newValue=$(param).parent().parent().children('td').eq(i).find("input:eq(0)").val();  
                data.push(newValue);  
            }

    }
        
	if(validItem(data)){
         $.ajax({ type:"post",
                url:"${base}/system/dictionary/dictItem/update",
                datatype:"json",
                data:{'id':id,
                      "dictId":dictId,
                      "name":data[0],
                      "code":data[1],
                      "value":data[2],
                      "showOrder":data[3]
                },                
				success: function(data){  
					noty({
	                         text:extendMessages(data).msg.message,
	                          layout:"center",
	                          timeout:2000,
	                          callback:{
	                             afterClose:function(){
	                                     refresh();
	                                        }
	                           }
	               });
               }
			});		
	  }       
}
function cancelAdd(){
  $("#addItem").hide();
}
function cancelEdit(param){
     var thisNode=$(param).parent().parent();
     var thisId=thisNode.children("input:eq(0)").val();
     for(var i=0;i<4;i++){
	     var startValue= $.trim(thisNode.find("td").eq(i).attr("startValue"));
	     thisNode.find("td").eq(i).text(startValue);
    }
	thisNode.children('td').eq(4).find('a').remove();
	thisNode.find("td").eq(4).append("<a href='javaScript:void(0);' onclick='deleteY('+thisId+',1)' class='no_tdn color_2'>删除</a>");
   
}

 $(function() {
  //第一个参数：  当前页   第二个 ：总页数   第三个：根路径   第四个：要跳转到哪一页
   originalpages(${pager.page},${pager.pages},"${base}/system/dictionary/dictItems/"+${dictId},${module});
 })
</script>
</head>
<body> 
	<div class="right_top"><span class="pl20 f14">数据项</span></div>

	<!-- 数据信息开始 -->
	<div class="date_list">
			<div class="ml10 mt10">
         <!--  <input type="button" class="btn_1" value="添加" id="uAdd" />   -->
               <input type="button" class="btn_1" value="添加" id="thisAdd" />
               <input type="button" class="btn_1" value="返回" id="callBack" />
			 </div> 
			 <div id="tblReuslt" class="mb10 center">
			  <form id="queryForm" method="post">
			  <input type="hidden" name="dictId" id="dictId" value="${dictId}">
			  <div class="date_table_3 tc">
				<table class="mt10 ml10 exchange_table" style="width:100%;" id="rateTable" border="0" cellspacing="0" cellpadding="0">
				   <thead>
						<tr>
							<th class="color_2 tab_bt tab_bl" width="250" >
							名称										
							</th>
							<th class="color_2 tab_bt"  width="150">
							代码										
							</th>
							<th class="color_2 tab_bt"  width="150">
							值										
							</th>
							<th class="color_2 tab_bt"  width="150">
							次序										
							</th>
							<th class="color_2 tab_bt" >
																	
							</th>
						</tr>
				</thead>
				<tbody>		
				[#if dictItems??]
				   [#list dictItems as item]										
						<tr>
						    <input type="hidden" value="${item.id!}">										
							<td class="br tab_bt editselect tab_bl tl" ondblclick="editItem(this);" startValue="${item.name!""}">
							${item.name!""}
						    </td>
                            <td class="br tab_bt editable tl" ondblclick="editItem(this);" startValue="${item.code!""}">
                            ${item.code!""}
						    </td>
							
							<td class="br tab_bt editable tr" ondblclick="editItem(this);" startValue="${item.value!""}">
							${item.value!""}
						    </td>
							
							<td class="br tab_bt editable tr" ondblclick="editItem(this);" startValue="${item.showOrder!""}">
							${item.showOrder!""}
						    </td>
							<td  class="br tab_bt">
							<a href="javaScript:void(0);" onclick="deleteY(${item.id!},1)" class='no_tdn color_2'>删除</a>
						    </td>										
						</tr>
					[/#list]
				 [/#if]
				 <tr id="addItem" class="none">
					<td class="br tab_bt tab_bl tl"><input type="text"  name="name" id="name"   class="required input_4"/></td>
					<td class="br tab_bt "><input type="text"  name="code" id="code"   class="required input_4"/></td>
					<td class="br tab_bt tr"><input type="text"  name="value" id="value"   class="required input_3"/></td>
					<td class="br tab_bt tr"><input type="text"  name="showOrder" id="showOrder"  class="required input_3" /></td>
					<td  class="br tab_bt">
							<a href="javaScript:void(0);" onclick="saveAdd(this)" class='no_tdn color_2'>保存</a>
							<a href="javaScript:void(0)" onclick="cancelAdd(this)" class='no_tdn color_2'>取消</a>
					</td>
				</tr>
				  </tbody>
				</table>
				</div>
			 </form>	
		</div>

		<!-- 页码显示 -->
		<div class="ChangePage01">
		   <div id="page" class="page"></div> 			
	    </div>
	</div>
	<!-- 数据信息结束 -->
 
			<!-- 用户权限列表结束 -->
	<div class="bottom"> </div>
</div>
 
</body>
</html>